How To Spool a Picture to a File
How To Spool a Picture to a File
/*
* How to spool a Picture to a File
*/
// Assumes inclusion of
pascal void PutPICTData(Ptr dataPtr, short byteCount);
void PictOut(void);
PicHandle pHand2;
short globalRef;
pascal void PutPICTData(Ptr dataPtr, short byteCount)
{
long longCount;
longCount = byteCount;
if (FSWrite( globalRef, &longCount, dataPtr) != noErr)
if (pHand2) /* Help QD take care of oddness in the picture */
(**pHand2).picSize += longCount;
}
void PictOut()
{
OSErr err;
short i,
vrefnum;
Point where; /* where to display dialog */
long longCount,
longZero;
SFReply reply; /* reply record */
CQDProcs myProcs;
CGrafPort myPort;
CGrafPtr myPortPtr,
oldPort;
Rect myRect,
pictRect;
GetPort(&oldPort);
myPortPtr = &myPort; /* initialize */
OpenPort(myPortPtr); /* set my port */
where.h = 20;
where.v = 20;
SFPutFile(where, "\pSave picture as: ", "\puntitled", nil, &reply);
if (!reply.good)
err = Create(reply.fName, reply.vRefNum, '????', 'PICT');
if (err != dupFNErr && err != noErr)
err = FSOpen(reply.fName, reply.vRefNum, & globalRef);
if (err)
pHand2 = nil;
SetStdCProcs(&myProcs);
myPortPtr->grafProcs = &myProcs;
myProcs.putPicProc = (Ptr)&PutPICTData;
SetRect(&myRect,100,100,300,300);
SetRect(&pictRect,0,0,500,500);
longZero = 0;
longCount = 4;
for (i = 1; i <= (512 + sizeof(Picture)) / 4; ++i)
err = FSWrite ( globalRef, &longCount, &longZero);
if (err)
pHand2 = OpenPicture(&pictRect);
MoveTo(5,10);
DrawString("\pThis is a picture saved to disk");
PaintRect(&myRect);
if (SetFPos( globalRef, fsFromStart, 512) != noErr)
longCount = sizeof(Picture);
if (FSWrite( globalRef, &longCount, *pHand2) != noErr)
if (FSClose( globalRef) != noErr)
myPortPtr->grafProcs = nil;
KillPicture (pHand2);
SetPort(oldPort);
} /* OutPICT */
main()
{
InitGraf(&thePort);
PictOut();
}